function createItemInfoTest(){
    var actualResult = createItemInfo();
console.log(actualResult);
    if(actualResult.hasOwnProperty('itemIndex') && 
        actualResult.itemIndex['ITEM000000'].hasOwnProperty('promotion') && 
        actualResult.itemIndex['ITEM000000'].hasOwnProperty('buyNum') && 
        actualResult.itemIndex['ITEM000000'].hasOwnProperty('pay') && 
        actualResult.hasOwnProperty('buyWhat') && 
        actualResult.hasOwnProperty('paySum') && 
        actualResult.hasOwnProperty('saveMoney') 
        ){
            console.log('createItemInfoTest passed!');
        }else{
            console.log('createItemInfoTest failed!');
        }
}

function readTagsInfoTest(){
    var itemInfo = {
        itemIndex:{
            ITEM000000:{
                name:'可口可乐',
                unit:'瓶',
                price:3.00,
                promotion:0,
                buyNum:0,
                pay:0
            },
            ITEM000001:{
                name:'雪碧',
                unit:'瓶',
                price:3.00,
                promotion:0,
                buyNum:0,
                pay:0
            }
        },
        buyWhat:[],
        paySum:0,
        saveMoney:0
    };
    var tags = [
      'ITEM000000',
      'ITEM000000',
      'ITEM000000',
      'ITEM000000',
      'ITEM000000',
      'ITEM000001-2.5',
    ];
    
    var actualResult = readTagsInfo(itemInfo,tags);
    
    if(actualResult.itemIndex['ITEM000000'].buyNum == 5 && 
        actualResult.itemIndex['ITEM000001'].buyNum == 2.5 && 
        actualResult.buyWhat[0] == 'ITEM000000' && 
        actualResult.buyWhat[1] == 'ITEM000001'){

            console.log('readTagsInfoTest passed!')

    }else{
        console.log('readTagsInfoTest failed!')
    }
}

function revisePromotionValueTest(){
    var itemInfo = {
        itemIndex:{
            ITEM000000:{
                name:'可口可乐',
                unit:'瓶',
                price:3.00,
                promotion:0,
                buyNum:0,
                pay:0
            },
            ITEM000001:{
                name:'雪碧',
                unit:'瓶',
                price:3.00,
                promotion:0,
                buyNum:0,
                pay:0
            },
            ITEM000005:{
                name:'荔枝',
                unit:'瓶',
                price:3.00,
                promotion:0,
                buyNum:0,
                pay:0
            },
            ITEM000006:{
                name:'方便面',
                unit:'瓶',
                price:3.00,
                promotion:0,
                buyNum:0,
                pay:0
            }
        },
        buyWhat:[],
        paySum:0,
        saveMoney:0
    };

    var actualResult = revisePromotionValue(itemInfo);
    if(actualResult.itemIndex['ITEM000000'].promotion == 1 &&
        actualResult.itemIndex['ITEM000001'].promotion == 1 &&
        actualResult.itemIndex['ITEM000005'].promotion == 1 &&
        actualResult.itemIndex['ITEM000006'].promotion == 0 ){
            console.log('revisePromotionValueTest passed!');
        }else{
            console.log('revisePromotionValueTest failed!');
        }
}

function calculateMoneyTest(){
    var itemInfo = {
        itemIndex:{
            ITEM000000:{
                name:'可口可乐',
                unit:'瓶',
                price:3.00,
                promotion:1,
                buyNum:2,
                pay:0
            },
            ITEM000001:{
                name:'雪碧',
                unit:'瓶',
                price:3.00,
                promotion:1,
                buyNum:3,
                pay:0
            },
            ITEM000005:{
                name:'荔枝',
                unit:'瓶',
                price:3.00,
                promotion:0,
                buyNum:4,
                pay:0
            },
            ITEM000006:{
                name:'方便面',
                unit:'瓶',
                price:3.00,
                promotion:0,
                buyNum:0,
                pay:0
            }
        },
        buyWhat:['ITEM000000','ITEM000001','ITEM000005'],
        paySum:0,
        saveMoney:0
    };
    var actualResult = calculateMoney(itemInfo);
    if(actualResult.itemIndex['ITEM000000'].pay == 6 &&
        actualResult.itemIndex['ITEM000001'].pay == 6 &&
        actualResult.itemIndex['ITEM000005'].pay == 12 &&
        actualResult.itemIndex['ITEM000006'].pay == 0 &&
        actualResult.paySum == 24 &&
        actualResult.saveMoney == 3 ){
            console.log('calculateMoneyTest passed!');
        }else{
            console.log('calculateMoneyTest failed!');
        }
}

function createShowStringTest(){
    var itemInfo = {
        itemIndex:{
            ITEM000000:{
                name:'可口可乐',
                unit:'瓶',
                price:3.00,
                promotion:1,
                buyNum:5,
                pay:12
            },
            ITEM000001:{
                name:'雪碧',
                unit:'瓶',
                price:3.00,
                promotion:1,
                buyNum:3,
                pay:6
            },
            ITEM000005:{
                name:'荔枝',
                unit:'斤',
                price:15,
                promotion:0,
                buyNum:2.5,
                pay:37.5
            },
            ITEM000006:{
                name:'方便面',
                unit:'袋',
                price:4.5,
                promotion:1,
                buyNum:3,
                pay:9
            }
        },
        buyWhat:['ITEM000000','ITEM000005','ITEM000006'],
        paySum:58.5,
        saveMoney:7.5
    };
    const dateDigitToString = num => (num < 10 ? `0${num}` : num);
    const currentDate = new Date(),
      year = dateDigitToString(currentDate.getFullYear()),
      month = dateDigitToString(currentDate.getMonth() + 1),
      date = dateDigitToString(currentDate.getDate()),
      hour = dateDigitToString(currentDate.getHours()),
      minute = dateDigitToString(currentDate.getMinutes()),
      second = dateDigitToString(currentDate.getSeconds()),
      formattedDateString = `${year}年${month}月${date}日 ${hour}:${minute}:${second}`;

    var expectResult = `***<没钱赚商店>收据***
打印时间：${formattedDateString}
----------------------
名称：可口可乐，数量：5瓶，单价：3.00(元)，小计：12.00(元)
名称：荔枝，数量：2.5斤，单价：15.00(元)，小计：37.50(元)
名称：方便面，数量：3袋，单价：4.50(元)，小计：9.00(元)
----------------------
总计：58.50(元)
节省：7.50(元)
**********************`;
    var actualResult = createShowString(itemInfo);
    if(actualResult == expectResult){
        console.log('createShowStringTest passed!');
    }else{
        console.log(expectResult);
        console.log(actualResult);
        console.log('createShowStringTest failed!');
    }
}

//createItemInfoTest();
//readTagsInfoTest();
//revisePromotionValueTest();
//calculateMoneyTest();
//createShowStringTest();

    const tags = [
      'ITEM000001',
      'ITEM000001',
      'ITEM000001',
      'ITEM000001',
      'ITEM000001',
      'ITEM000003-2.5',
      'ITEM000005',
      'ITEM000005-2',
    ];

    printReceipt(tags);

//     class myClass{
//         constructor (){
//             this.student = {};
//         }
//     }
// var classTest = new myClass();
// classTest.student['name'] = 'abc';
// console.log(classTest);





